package graphics.effects;
import main.Config;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;

import graphics.system.GLTools;
import graphics.system.Shader;
import graphics.system.Texture;
import graphics.system.TextureContainer;
public final class Compositor {
	private static Shader compsh;
	private static Shader shadow;
	public static Shader specular;
	public static Texture noisetex;
	public static Shader noisefilter;
	public static float mblur;
	public static Shader blur;
	public static void init() {
		compsh = new Shader();
		compsh.load("shader/compositor.c");
		shadow = new Shader();
		shadow.load("shader/shadow.c");
		specular = new Shader();
		specular.load("shader/specular.c");
		noisefilter = new Shader();
		noisefilter.load("shader/noise.c");
		blur = new Shader();
		blur.load("shader/simpleblur.c");
		noisetex = TextureContainer.getTexture("noise");
		mblur = 0f;
	}
	public static void draw(float w, float h, float zoom) {
		compsh.enable();
		// Is set in drawTexRect
		/*
		 * GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, Layer.colormap.getTexId());
		 */
		GL13.glActiveTexture(GL13.GL_TEXTURE1);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, Layer.warp.getTexId());
		GL13.glActiveTexture(GL13.GL_TEXTURE2);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, Layer.particles.getTexId());
		GL13.glActiveTexture(GL13.GL_TEXTURE3);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, Layer.shadow.getTexId());
		compsh.setParami("color", 0);
		compsh.setParami("warp", 1);
		compsh.setParami("shadow", 3);
		compsh.setParami("particles", 2);
		compsh.setParamf("sw", 1.0f / w);
		compsh.setParamf("sh", 1.0f / h);
		compsh.setParamf("zoom", zoom);
		compsh.setParamf("wstrength", 150);
		compsh.setParamf("motionblur", 1 - mblur);
		compsh.setParamf("brightness", 0.58f);
		compsh.setParamf("contrast", 1.35f);
		GLTools.drawTexRect(w / 2.0f, h / 2.0f, w, h, Layer.colormap.getTexId());
		compsh.disable();
	}
	public static void enableShadowRender() {
		shadow.enable();
		shadow.setParami("color", 0);
	}
	public static void disableShadowRender() {
		shadow.disable();
	}
	public static void reloadShader() {
		compsh.delete();
		shadow.delete();
		specular.delete();
		blur.delete();
		noisefilter.delete();
		init();
	}
	public static void setMblur(float f) {
		mblur = f;
	}
}
